package com.lt73.publisher.controller;

import com.lt73.publisher.entity.Student;
import com.lt73.publisher.event.StudentEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;


/**
 * @Author: hanxiao
 * @Date: 2022/4/14 10:52
 */
@RestController
public class DemoController {
    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @GetMapping("/insert")
    public Object insertMessage() {

        //注册用户
        Student student = new Student();
        student.setId(1);
        student.setName(LocalDateTime.now().toString());
        StudentEvent studentEvent = new StudentEvent(this, student);
        eventPublisher.publishEvent(studentEvent);

        return studentEvent.getStudent();


    }
}
